package com.jadcon.bedbreakfast.web;

import java.sql.SQLException;
import java.text.ParseException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.jadcon.bedbreakfast.domain.ReservationService;
import com.jadcon.bedbreakfast.domain.Suite;
import com.jadcon.bedbreakfast.domain.SuiteService;

@Controller
@SessionAttributes("suiteSearch")
public class SuiteController {

	@Autowired
	private SuiteService SuiteService;
	@Autowired
	private ReservationService ReservationService;

	@RequestMapping("/suite.html")
	public ModelAndView suite() throws SQLException {
		System.out.println("SuiteController.suite() begin...");

		List<Suite> suiteList = SuiteService.getSuiteList();

		ModelAndView mav = new ModelAndView("suite");
		mav.addObject("suiteList", suiteList);
		return mav;

	}

	@RequestMapping("/search.html")
	public ModelAndView search() {
		System.out.println("SuiteController.search() begin...");
		return new ModelAndView("search");
	}

	@RequestMapping("/searchresults.html")
	public ModelAndView searchResults(@RequestParam String checkIn,
			String checkOut) throws ParseException, SQLException {
		System.out.println("SuiteController.searchResults() begin...");
		
		List<Suite> suiteList = ReservationService.equalsDateRange(checkIn, checkOut);

		ModelAndView mav = new ModelAndView("searchResults");
		mav.addObject("suiteList", suiteList);
		return mav;
		

	}

}
